package com.twu.biblioteca;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: mini server
 * Date: 9/20/13
 * Time: 3:33 AM
 * To change this template use File | Settings | File Templates.
 */
public class ReserveABookView implements IView{

    private Library library;

    public ReserveABookView()
    {
        library = Library.GetInstanceOfLibrary(Library.OLD_INSTANCE);
    }

    public ReserveABookView(int code) // A constructor useful for testing or resetting view.
    {
        library = Library.GetInstanceOfLibrary(code);
        if (library == null)
        {
            throw new IllegalArgumentException("Unknown Library Code " + code);
        }
    }

    @Override
    public String display()
    {
        if(!BibliotecaApp.user.authenticate())
        {
            return "Please login to avail this facility\n";
        }


        String result = "Enter the id of the book you want to reserve:\n";
        IView allBooksView = new AllBooksView();
        result += allBooksView.display();
        return result;
    }

    @Override
    public IView interact()
    {
        if(!BibliotecaApp.user.authenticate())
        {
            return new MenuView();
        }

        String selectedBookId;
        Scanner selectedOptionScanner = new Scanner(System.in);
        selectedBookId = selectedOptionScanner.nextLine();

        if (library.reserve(Inventory.BOOK_INVENTORY, selectedBookId))
        {
            System.out.println("Thank You! Enjoy the book.\n");
        }
        else
        {
            System.out.println("Sorry we don't have that book yet.\n");
        }

        return new MenuView();  //To change body of implemented methods use File | Settings | File Templates.
    }
}
